package edu.yuhf.dao;

import com.yuhf.dbutils.JdbcTemplate;
import edu.yuhf.dao.iface.AdDao;
import edu.yuhf.domain.Ad;

import java.util.ArrayList;
import java.util.List;

public class AdJdbcDaoImpl implements AdDao {
    @Override
    public List<Ad> queryProvince() {
        String sql = "select id,code,name from ad_name where length(code)=2";
        List<Ad> list = JdbcTemplate.query(sql,rs -> {
            Ad ad = new Ad(rs.getInt(1),rs.getString(2),rs.getString(3));
            return ad;
        });
        return list;
    }

    @Override
    public List<Ad> queryCity(String currentProvinceCode) {
        String sql = "select id,code,name from ad_name where length(code)=4 and left(code,2)=?";
        return JdbcTemplate.query(sql,rs -> {
            Ad ad = new Ad(rs.getInt(1),rs.getString(2),rs.getString(3));
            return ad;
        },currentProvinceCode);
    }
}
